home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-PR / MPW / Scripts / shlb2stub < prev    next >
Encoding:
Text File  |  1998-11-24  |  4.7 KB  |  151 lines  |  [TEXT/MPS ]

  1. # shlb2stub - Create a stub library from the export list supplied by a shared library
  2. #
  3. # Copyright © 1998, Apple Computer, Inc., All Rights Reserved
  4. # Written by Greg Branche
  5. #
  6. #    History:
  7. #
  8. #        04/21/98    GAB        Initial version
  9. #        04/22/98    GAB        1.0d2
  10. #                                Corrected expression used to extract fragment name. Names have no
  11. #                                    restrictions on which characters can be used.
  12. #                                Added check for existenced of proper version of DumpPEF.
  13. #        04/23/98    GAB        1.0d3
  14. #                                Add check to ensure that input file is an actual PEF file.
  15. #                                Add Commando dialog.
  16. #        11/24/98    cae        1.0d4
  17. #                                Added "Set Echo 0" at start of script.
  18. #                                Updated version number.
  19. #
  20. #    Usage:
  21. #        shlb2stub [option…] inputFile
  22. #
  23. #            -p                # show progress
  24. #            -o filename        # specify name of output file, default = input filename with ".stub" appended
  25. #
  26.  
  27. Set Echo 0
  28.  
  29. set version 1.0d4
  30. unset progress
  31. Alias Usage 'Echo >dev:stderr "# Usage: {0} [-p] [-o filename] libraryName∂n"; Exit 1'
  32.  
  33. # process command line
  34. Loop
  35.     break if {#} == 0
  36.     if "{1}" =~ /-≈/
  37.         if "{1}" =~ /-[oO]/
  38.             shift 1
  39.             set outputFile "{{1}}"
  40.         else if "{1}" =~ /-[pP]/
  41.             set progress 1
  42.         else
  43.             echo >dev:stderr "# {0} - unsupported option: ∂"{1}∂""
  44.             Usage
  45.         end
  46.     else
  47.         if "{{inputFile}}" == ""
  48.             set inputFile "{{1}}"
  49.         else
  50.             echo >dev:stderr "# {0} - more than one input file not allowed, ∂"{1}∂" ignored."
  51.         end
  52.     end
  53.     shift 1
  54. End
  55.  
  56. if "{inputFile}" == ""
  57.     Echo >dev:stderr "# {0} - An input library must be supplied."
  58.     Usage
  59. End
  60.  
  61. if {progress}
  62.     echo "# {0} - Version {version}. Create a stub library from a shared library."
  63.     echo "# Copyright © 1998, Apple Computer, Inc, All Rights Reserved."
  64.     Echo "#"
  65. end >dev:stderr
  66.  
  67. if "{{outputFile}}" == ""
  68.     set outputFile "{{inputFile}}".stub
  69. end
  70.  
  71. # must have version 2.3d1 or later of DumpPEF (for the -container option support)
  72. Unset ®1 ®2 ®3 ®4
  73. (evaluate "`VersionList DumpPEF -h -raw | StreamEdit -d -e '/DumpPEF[ ∂t]+(≈)®1/ Print ®1'`" =~ /([0-9]+)®1.([0-9]+)®2(.([0-9]+)®3)*(([AaBbDd]«1»[0-9]+)*)®4/) ∑dev:null
  74. if {®1} < 2 || ({®1} == 2 && {®2} < 3)
  75.     echo >dev:stderr "# {0} - Must have DumpPEF version 2.3d1 or later available."
  76.     Exit 2
  77. end
  78.  
  79. set exit 0
  80. dumppef "{{inputFile}}" ∑dev:null
  81. if {status} != 0
  82.     echo "# {0} - “{inputFile}” doesn't appear to be a valid shared library file."
  83.     exit 2
  84. end >dev:stderr
  85. set exit 1
  86.  
  87. #########################################################################################################
  88. # OK, all preflighting is done now. It's time to get to work.
  89.  
  90. # extract container headers and count number of containers in input file
  91. set containerCount `dumppef "{{inputFile}}" -do e | StreamEdit -d -e '/Container ∂[[0-9]+∂]/ Print' | count -l`
  92.  
  93. if {progress}
  94.     echo "# -> Discovered {containerCount} PEF containers in “{inputFile}”."
  95. end >dev:stderr
  96.  
  97. set counter 1
  98. loop
  99.     if {progress}
  100.         echo "# ->   Processing container #{counter}."
  101.     end >dev:stderr
  102.     
  103.     # extract important info from header, and format as options to MakeStub
  104.     set fragName "`DumpPEF -container {counter} "{{inputFile}}" -do e | StreamEdit -d ∂
  105.         -e '/Container ∂[[0-9]+∂] ∂((≈)®1∂) ∂[≈∂]/ Print ®1' ∂
  106.         #`"
  107.     set makeStubOpts "`DumpPEF -container {counter} "{{inputFile}}" -do h | StreamEdit -d ∂
  108.         -e '/oldDefVersion[ ∂t]+=[ ∂t]+([0-9]+)®1/ Print " -verDef "®1' ∂
  109.         -e '/oldImpVersion[ ∂t]+=[ ∂t]+([0-9]+)®1/ Print " -verImp "®1' ∂
  110.         -e '/currentVersion[ ∂t]+=[ ∂t]+([0-9]+)®1/ Print " -verCur "®1' ∂
  111.         -e '/architectureID[ ∂t]+=[ ∂t]+0x6D36386B/ Print " -arch m68k"' ∂
  112.         -e '/architectureID[ ∂t]+=[ ∂t]+0x70777063/ Print " -arch pwpc"' ∂
  113.         #`"
  114.  
  115.     # extract list of exported symbols
  116.     DumpPEF "{{inputFile}}" -container {counter} -ldr x | StreamEdit -d ∂
  117.         -e '/≈TVector≈[ ∂t]+∂[[0-9A-F]+∂][ ∂t]+([¬ ]+)®1∞/ Print "#{code}∂n"®1' ∂
  118.         -e '/≈Data≈[ ∂t]+∂[[0-9A-F]+∂][ ∂t]+([¬ ]+)®1∞/ Print "#{data}∂n"®1' ∂
  119.         >"{TempFolder}"__lib_exports_{counter}__
  120.     
  121.     # Now we can build the stub library
  122.     if {progress}
  123.         echo "# ->   Building stub library for container “{fragName}”."
  124.     end >dev:stderr
  125.     
  126.     MakeStub {MakeStubOpts} -fragName "{fragName}" "{TempFolder}"__lib_exports_{counter}__ -o "{TempFolder}"StubLib{counter}
  127.     Delete -i -y "{TempFolder}"__lib_exports_{counter}__
  128.  
  129.     # Neeeeeexxxxtttttt!
  130.     evaluate counter += 1
  131.     break if {counter} > {containerCount}
  132. end
  133.  
  134. # Now combine the separate stubs into a single stub library file
  135. if "`files "{TempFolder}"StubLib[0-9]+`"
  136.     if {progress}
  137.         echo "# -> Combining separate stubs into single “{outputFile}” stub library file."
  138.     end >dev:stderr
  139.     
  140.     Delete -i "{{outputFile}}"    # delete old library first
  141.     MergeFragment `files -f "{TempFolder}"StubLib[0-9]+` "{{outputFile}}"
  142.     SetFile -c 'MPS ' -t stub "{{outputFile}}"
  143. end
  144. Delete -i -y "{TempFolder}"StubLib[0-9]+
  145.  
  146. if {progress}
  147.     echo    # leave a blank line after all the spewing
  148. end >dev:stderr
  149.  
  150. Exit 0
  151.